<template>
	<view class="list-page" :style="loading ? 'opacity: 0;' : 'opacity: 1;'">
		<!--  v-model="dataList" @query="queryList" -->
		<!--  refresher-only @onRefresh="onRefresh" -->
		<pageTxt>
			<listTabCom class="listTabCom" :tabList="topTabList" @topTabClick="topTabClick" :current="topTabIndex"></listTabCom>
			<!-- 收款管理 -->
			<collectionManagement ref="collectionManagement" :option="{}" :conentHeight="conentHeight" v-if="currIndex == 0"></collectionManagement>
			<!-- 付款管理 -->
			<attachmentManagement ref="attachmentManagement" :option="{}" :conentHeight="conentHeight" v-if="currIndex == 1"></attachmentManagement>
		</pageTxt>
	</view>
</template>

<script>
import collectionManagement from './components/collectionManagement/collectionManagement.vue';
import attachmentManagement from './components/attachmentManagement/attachmentManagement.vue';
import braces from 'braces';
export default {
	components: {
		attachmentManagement,
		collectionManagement
	},
	data() {
		return {
			loading: true,
			dataList: [],
			conentHeight: 0,
			refresh: false,
			refreshItem: false,
			topTabIndex: '-1',
			currIndex: '-1',
			refresh: false,
			topTabList: [
				{
					name: '收款管理',
					index: 0
				},
				{
					name: '付款管理',
					index: 1
				}
			]
		};
	},
	onLoad(option) {
		this.getHeight();
		if (option.tabIndex) {
			this.topTabIndex = option.tabIndex;
			this.currIndex = this.topTabList[this.topTabIndex].index;
		}
		// 通过字段权限判断是否显示收款单OR付款单
		this.tabShowFunc();
		// 页面参数处理
		this.$nextTick(() => {
			if (option.project_name) {
				switch (Number(this.currIndex)) {
					case 0:
						if (!this.$refs.collectionManagement) return;
						this.$refs.collectionManagement._data.searchForm.project_name = option.project_name;
						this.$refs.collectionManagement.searchFunc();
						break;
					case 1:
						// this.$refs.attachmentManagement.refreshItemFunc();
						break;
					default:
				}
			}
		});
	},
	onShow() {
		this.$nextTick(() => {
			switch (Number(this.currIndex)) {
				case 0:
					this.$refs.collectionManagement.refreshItemFunc();
					break;
				case 1:
					this.$refs.attachmentManagement.refreshItemFunc();
					break;
				default:
			}
		});
	},
	methods: {
		getHeight() {
			// 创建节点查询
			let that = this;
			const systemInfo = uni.getSystemInfoSync();
			const query = uni.createSelectorQuery().in(that);
			query.select('.listTabCom').boundingClientRect();
			query.exec((res) => {
				that.conentHeight = systemInfo.screenHeight - (res[0].height + 20); //组件可用高度 20状态栏高度（动态获取高度不包含状态栏高度）
				setTimeout(() => {
					that.loading = false;
				}, 200);
			});
		},
		topTabClick(index) {
			this.topTabIndex = index;
			this.currIndex = this.topTabList[index].index;
		},
		// 收款/付款tab控制显示隐藏
		tabShowFunc() {
			// 通过字段权限判断是否显示收款单OR付款单
			if (
				!this.$fieldShowFunc('sfk_sklx') &&
				!this.$fieldShowFunc('sfk_skr') &&
				!this.$fieldShowFunc('sfk_skrq') &&
				!this.$fieldShowFunc('sfk_skje') &&
				!this.$fieldShowFunc('sfk_skzh') &&
				!this.$fieldShowFunc('sfk_skdzt') &&
				!this.$fieldShowFunc('sfk_skpz') &&
				!this.$fieldShowFunc('sfk_skbz')
			) {
				this.topTabList.splice(0, 1);
				this.currIndex = 1;
				this.topTabIndex = 0;
			}
			if (
				!this.$fieldShowFunc('sfk_fklx') &&
				!this.$fieldShowFunc('sfk_glcgjsd') &&
				!this.$fieldShowFunc('sfk_gys') &&
				!this.$fieldShowFunc('sfk_sqje') &&
				!this.$fieldShowFunc('sfk_skzh2') &&
				!this.$fieldShowFunc('sfk_fkzh') &&
				!this.$fieldShowFunc('sfk_fkzt') &&
				!this.$fieldShowFunc('sfk_fkbz') &&
				!this.$fieldShowFunc('sfk_ssqr') &&
				!this.$fieldShowFunc('sfk_sqsj')
			) {
				this.topTabList.splice(1, 1);
				this.currIndex = 0;
				this.topTabIndex = 0;
			}
		}
	}
};
</script>

<style lang="scss" scoped></style>
